package com.grape.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Cascade;

@Entity
@Table(name = "T_USER")
// 对象可以转成xml传输
@XmlRootElement(name = "user")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "U_ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	@Column(name = "U_USERNAME")
	private String username; // 用户名
	@Column(name = "U_PASSWORD")
	private String password; // 密码
	@Column(name = "U_NAME")
	private String name; // 姓名
	@Column(name = "U_EMAIL")
	private String email; // 邮箱
	@Column(name = "U_PHONE_NUM")
	private String phoneNum; // 手机号
	@Column(name = "U_PICTURES",length = 1000)
	private String pictures; // 用户的图片们
	@Column(name = "U_PREFER")
	private String prefer; // 用户最喜欢的一张,默认展示的一张

	@OneToMany(fetch = FetchType.EAGER, // 取消延迟加载
			targetEntity = Bookmark_Box.class, // 目标对象
			orphanRemoval = true,// 孤儿删除
			mappedBy="user") // 多方维护外键
	@OrderBy()
	private List<Bookmark_Box> bbs = new ArrayList<>();

	public User() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", password=" + password + ", name=" + name + ", email="
				+ email + ", phoneNum=" + phoneNum + ", pictures=" + pictures + ", prefer=" + prefer + ", bbs=" + bbs
				+ "]";
	}

	public User(Integer id, String username, String password, String name, String email, String phoneNum,
			String pictures, String prefer, List<Bookmark_Box> bbs) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.name = name;
		this.email = email;
		this.phoneNum = phoneNum;
		this.pictures = pictures;
		this.prefer = prefer;
		this.bbs = bbs;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public String getPictures() {
		if (pictures == null) {
			return "";
		}
		return pictures;
	}

	public void setPictures(String pictures) {
		this.pictures = pictures;
	}

	public String getPrefer() {
		if (prefer == null) {
			return "";
		}
		return prefer;
	}

	public void setPrefer(String prefer) {
		this.prefer = prefer;
	}

	public List<Bookmark_Box> getBbs() {
		return bbs;
	}

	public void setBbs(List<Bookmark_Box> bbs) {
		this.bbs = bbs;
	}

}
